<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>向字符串添加空格</title>
</head>
<body>
  <script>
    function fn(s, str) {
      let a = '', b = 0
      for (let i = 0; i < str.length; i++) {
        a += s.slice(b, str[i])
        a += ' '
        b = str[i]
      }
      a += s.slice(b, s.length)
      return a
    }
    console.log(fn('EnjoyYourCoffee', [5, 9]))
  </script>
</body>
</html>